package com.hejjon.core.utils;

import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;

import java.nio.charset.StandardCharsets;
import java.util.Date;

public class FileUtils {


    /**
     * 根据文件名，构建HttpHeaders
     *
     * @param fullFileName 文件名称
     * @return org.springframework.http.HttpHeaders
     */
    public static HttpHeaders getHttpHeaders(String fullFileName) {
        HttpHeaders httpHeaders = new HttpHeaders();
        String fileName = new String(fullFileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
        httpHeaders.add("Content-Disposition", "attachment; filename=" + fileName);
        // httpHeaders.setContentDispositionFormData("attachment", fileName);
        httpHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        return httpHeaders;
    }

    public static String getFileName(String prefix, String suffix) {
        String dayStr = DateTimeUtil.datetime2Str(new Date(), DateTimeUtil.TIME_FORMAT);
        return prefix + "_" + dayStr + suffix;
    }


}
